//
//  RLMiddleTitleView.m
//  RelaxLinkProduct
//
//  Created by relax on 2017/11/26.
//  Copyright © 2017年 relax. All rights reserved.
//

#import "RLMiddleTitleView.h"

@interface RLMiddleTitleView ()

@property (weak, nonatomic) IBOutlet UIStackView *stackView;

@property (weak, nonatomic) IBOutlet UIView *lineView;

@end


@implementation RLMiddleTitleView

+ (instancetype)middleTitleView {
    return [[UINib nibWithNibName:@"RLMiddletTitleView" bundle:nil] instantiateWithOwner:nil options:nil].firstObject;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    self.backgroundColor = [UIColor clearColor];
    self.rl_width = 180;
    self.rl_height = 40;
    
    static NSUInteger index = 0;
    
    for (UIButton *btn in self.stackView.subviews) {
        btn.tag = index;
        [btn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted];
        [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        index++;
    }
}

- (void)btnClick:(UIButton *)btn {
    // 小白条移动动画
    [UIView animateWithDuration:0.25 animations:^{
        self.lineView.rl_centerX = btn.centerX;
    }];
    
    self.buttonClicked ? self.buttonClicked(btn.tag) : nil;
}

- (void)moveLineViewWithScale:(CGFloat)scale {
    self.lineView.rl_x = self.stackView.width * scale;
}

@end
